import matplotlib.pyplot as plt
import numpy as np
import os

def cr():
    x_data = ['MID', 'EDF', 'INS', 'SRPT', 'FB', 'THR', 'OPTFB', 'RM', 'SEDF', 'SALL', 'FIFO', 'FEDF']
    cr_data = [0.7978425141010972, 0.8954041910615047, 0.9107883271530585, 0.8920900660301321, 0.9141974667170055, 0.9141974667170055, 0.9209106581024377, 0.8286750475301631, 0.9176723502109876, 0.8923642593788409, 0.696743152059281, 0.6986161952327195]
    plt.bar(x_data,cr_data,color="deepskyblue",label="Average Completion Rate")

    #line
    ave_us_data = [0.73807, 0.7539292000000001, 0.823638, 0.8070065999999998, 0.7942980000000003, 0.7942980000000003, 0.8283179999999998, 0.6678254000000001, 0.8280392000000002, 0.7547375999999999, 0.6644099999999998, 0.6641756000000001]
    worst_us_data = [0.70614, 0.68821, 0.79029, 0.77576, 0.74779, 0.74779, 0.80421, 0.65365, 0.8028, 0.73308, 0.58183, 0.58183]
    ave_Comp_ratio = [0.828575277568845, 0.8463792000179622, 0.9246359890880922, 0.9059651761958755, 0.8916981936975873, 0.8916981936975873, 0.9298898705614242, 0.7497169864274731, 0.9295768829215174, 0.847286729458783, 0.7458827755761868, 0.7456196324528218]
    worst_Comp_ratio =  [0.7927298853800644, 0.7726012326414226, 0.8871987157178621, 0.8708869854171111, 0.8394871852442269, 0.8394871852442269, 0.9028256452282857, 0.7338033386845089, 0.9012427450408074, 0.8229733825791169, 0.6531764653052977, 0.6531764653052977]
    plt.plot(x_data, ave_us_data, color = "sandybrown", marker='o', ms=3, label="ave_us")
    plt.plot(x_data, worst_us_data, color = "crimson", marker='o', ms=3, label="worst_us")
    plt.plot(x_data, ave_Comp_ratio, color = "plum", marker='o', ms=3, label="ave_compratio")
    plt.plot(x_data, worst_Comp_ratio, color = "indigo", marker='o', ms=3, label="worst_compratio")
    plt.legend()
    plt.title('Completion rate & US & CompRatio')
    graph_path = os.path.dirname(os.path.abspath(__file__)) + '/graph/'
    if not os.path.isdir(graph_path):
        os.makedirs(graph_path)
    file_name = graph_path + __file__.split('/')[-1].split('.')[0]
    plt.savefig(f"{file_name}.pdf", bbox_inches='tight')
    plt.close()


if __name__ == '__main__':
    cr()
        
